

package com.wzl.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.wzl.common.CommonMetaObjectHandler;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;


/**
 * @author wzl
 * @date 2020-03-25 4:48 下午
 * @description Mybatis配置
 */

@Configuration
@MapperScan("com.wzl.dao")
@EnableTransactionManagement
public class MybatisPlusConfig  {

    /**
     * mybatis拦截器
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        // 向Mybatis过滤器链中添加分页拦截器
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));

        // 还可以添加其它的拦截器
        return interceptor;
    }



    /**
     * 自动填充数据
     */
    @Bean
    @ConditionalOnMissingBean
    public CommonMetaObjectHandler mateMetaObjectHandler() {
        return new CommonMetaObjectHandler();
    }

}
